import os
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtMultimediaWidgets import *


class SecondWindow(QMainWindow):
    start_signal = pyqtSignal(str, int)
    stop_signal = pyqtSignal(str, int)
    null_signal = pyqtSignal(str)

    def __init__(self):
        super().__init__()
        self.initUI()
        # 自定义工作信号

    def initUI(self):
        center_container = QWidget()

        # container = QStackedLayout(center_container)
        layout1 = QVBoxLayout(center_container)

        # 创建标签放图象
        self.pic_lable = QLabel()
        pixmap = QPixmap(r"C:\pythonProject1\gra_design\data\test_img\1.png")
        self.pic_lable.setPixmap(pixmap)

        # 创建工作按钮、暂停按钮
        self.start_btn = QPushButton("开始工作")
        self.stop_btn = QPushButton("暂停工作")

        # 为按钮的点击绑定槽
        self.start_btn.clicked.connect(self.start_emit)
        self.stop_btn.clicked.connect(self.stop_emit)

        # 为接受按钮{信号连接槽
        self.start_signal.connect(self.start_mylot)
        self.stop_signal.connect(self.stop_mylot)

        layout1.addWidget(self.pic_lable)
        layout1.addWidget(self.start_btn)
        layout1.addWidget(self.stop_btn)

        self.setWindowTitle('操作界面')
        self.setCentralWidget(center_container)
        self.setGeometry(700, 300, 500, 300)

    def start_emit(self):
        '''
        发送开始工作信号
        :return:
        '''
        self.start_signal.emit('1', 888)

    def start_mylot(self, data, num):
        '''
        该槽接收开始工作信号
        :param data:
        :param num:
        :return:
        '''
        print(f"开始工作: {data},{num}")
        print(f"开始指令: {num}")

    def stop_emit(self):
        '''
        发送停止工作信号
        :return:
        '''
        self.stop_signal.emit('0',666)

    def stop_mylot(self, data, num):
        '''
        该槽接收停止工作信号
        :return:{
        '''
        print(f"暂停工作: {data}")
        print(f"暂停信号: {num}")


if __name__ == '__main__':
    app = QApplication(sys.argv)
    mainWindow = SecondWindow()
    mainWindow.show()
    sys.exit(app.exec_())
